package org.nuplay;

import java.net.InetAddress;

import javax.swing.JLabel;

public class NuPlayWiiMoteSend implements Runnable {

	private boolean stopped;
	private NuPlayWiiMoteConnector connector;
	private int fps = 25;
	private int adjusting  = 8;
	private int delay = 1000 / (fps * adjusting);
	private int counter = 0;

	public NuPlayWiiMoteSend(Integer in_channel, NuPlayWiiMoteDevice in_device, InetAddress address, JLabel in_label) {
		System.out.println("NuPlayWiiMoteSend");
		connector = new NuPlayWiiMoteConnector(in_channel, in_device, address, in_label);
		stopped = false;
		counter = 0;
		Thread thread = new Thread(this);
		thread.start();
	}

	
	public void run() {
		while (!stopped) {
			counter++;
			try {
				Thread.sleep(delay);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			connector.adjust();
			if (counter > adjusting) {
				connector.send_status();
				counter = 0;
			}
		}  
		connector.close();
	}
	public void close() {
		stopped = true;
	}

}
